<?
	session_start();
	ob_start();
	global $TRDF;
	if(empty($_SESSION['user_login'])){
		echo"
		<br><br><br><br><br>
		<div align=center style='font-family: verdana; font-size: 10px; color: red;'>
		 Maaf, Halaman ini tidak bisa diakses. <br>
		 <a href='../index.php'>Anda harus login terlebih dahulu.</a><br><br><BR>
		 <span style='color:black;'>HRD Information System - Karyawan dot net</span>
		</div>
		";
		exit();
	}

include("../lib/config.php");
?>
<style type="text/css">
body,table{
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:10px;
}
</style>
<link rel="stylesheet" type="text/css" href="../style/print.css" media="print" />
<title>Report:: Komposisi Tenaga Kerja Karyawan dot net</title>
<?
	if($HTTP_GET_VARS['excel'] == "yes"){}
	else{
?>
<div style="color:blue;" class="print_ignore">
[ <a href="Javascript:window.print();" style="text-decoration:none;">CETAK</a> | <a href="<?=$PHP_SELF?>?excel=yes" style="text-decoration:none;">Export to Excel</a> ]
</div>
<?
	}
?>
<hr noshade="noshade" size="-2" color="#666666" />
<table width="100%">
 <tr>
  <td>KOMPOSISI TENAGA KERJA Karyawan dot net<br>
  PERIODE <?=date("M Y")?>
  </td>
 </tr>
 <tr>
  <td><br>I. BERDASARKAN STATUS KEPEGAWAIAN<br><br></td>
 </tr>
 <tr>
  <td>
   <table cellpadding="2" cellspacing="0" width="100%" border="1">
    <tr bgcolor="#CCCCCC">
     <td><b>Status Kepegawaian</b></td>
     <td><b>Jumlah</b></td>
     <td><b>Presentasi</b></td>
    </tr>
    <tr>
     <td colspan="3"><b>Pegawai</b></td>
    </tr>
    <?
	// get status pegawai : tetap dan percobaan
	//$sStsPeg	= mssql_query("SELECT * FROM VRepEmpStatus WHERE Nama IN ('Tetap','Percobaan') ",$conn);
	//$stotal		= mssql_query("SELECT * FROM VRepEmpStatus WHERE Nama IN ('Tetap','Percobaan')",$conn);
	$stotal		= mssql_query("SELECT * FROM VLatestKarir A, VStatusKaryawan B WHERE (stat_kar1=B.kode OR stat_kar2=B.kode) AND B.Nama IN ('Tetap','Percobaan') AND Jenis NOT IN ('U','H')",$conn);
	$ptotal		= mssql_num_rows($stotal);
	//while($rStsPeg = mssql_fetch_array($sStsPeg)){
		echo"
		<tr>
		 <td>Tetap</td>";
		 // get jumlah per status
		 $sCntStsPeg = mssql_query("SELECT * FROM VLatestKarir A, VStatusKaryawan B WHERE (stat_kar1=B.kode OR stat_kar2=B.kode) AND B.Nama IN ('Tetap') AND Jenis NOT IN ('U','H')",$conn);
		 $cCntStsPeg = mssql_num_rows($sCntStsPeg);
		 echo"<td align=right>$cCntStsPeg</td>";
		 echo"<td align=right>";
		 if($cCntStsPeg == NULL){
		 	echo"0";
		 }
		 else{
			 echo round(($cCntStsPeg/$ptotal)*100,2);
		 }
		 echo"%</td>";
		echo"</tr>";
		
		echo"
		<tr>
		 <td>Percobaan</td>";
		 // get jumlah per status
		 $sCntStsPeg = mssql_query("SELECT * FROM VLatestKarir A, VStatusKaryawan B WHERE (stat_kar1=B.kode OR stat_kar2=B.kode) AND B.Nama IN ('Percobaan') AND Jenis NOT IN ('U','H')",$conn);
		 $cCntStsPeg = mssql_num_rows($sCntStsPeg);
		 echo"<td align=right>$cCntStsPeg</td>";
		 echo"<td align=right>";
		 if($cCntStsPeg == NULL){
		 	echo"0";
		 }
		 else{
			 echo round(($cCntStsPeg/$ptotal)*100,2);
		 }
		 echo"%</td>";
		echo"</tr>";
	//}
	?>
     <tr>
      <td align="right"><b><i>Sub Total</i></b></td>
      <td align="right"><b><?=$ptotal;?></b></td>
      <td>&nbsp;</td>
     </tr>
    <tr>
     <td colspan="3"><b>Non Pegawai</b></td>
    </tr>
    <tr>
     <td>Kontrak Waktu Tertentu (PKUWT)</td>
     <?
	 // perjanjian kerja biasa
		 $sCntStsPeg1 = mssql_query("SELECT * FROM VLatestKarir A, VStatusKaryawan B WHERE (stat_kar1=B.kode OR stat_kar2=B.kode) AND B.Nama IN ('Perjanjian Kerja Khusus (Individu)') AND Jenis NOT IN ('U','H')",$conn);
		 $cCntStsPeg1= mssql_num_rows($sCntStsPeg1);
	 ?>
     <td align="right"><?=$cCntStsPeg1;?></td>
     <td align="right">&nbsp;</td>     
    </tr>
    <tr>
     <td>Kontrak Lembaga (Outsourching)</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>     
    </tr>
     <tr>
      <td align="right"><b><i>Sub Total</i></b></td>
      <td align="right">&nbsp;</td>
      <td>&nbsp;</td>
     </tr>
     <tr>
      <td align="left" style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;"><b><i>TOTAL</i></b></td>
      <td align="right"  style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;"><b><?=($ptotal+$cCntStsPeg1)?></b></td>
      <td style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;">&nbsp;</td>     
     </tr>
   </table>
  </td>
 </tr>
 <tr>
  <td><br>
  II. BERDASARKAN LOKASI PENEMPATAN<br><br>
  <table border="1" width="100%" cellpadding="2" cellspacing="0">
   <tr bgcolor="#CCCCCC">
    <td><b>STATUS</b></td>
    <td width="50" align="center"><b>SIHO</b></td>
    <td width="50" align="center"><b>SBU</b></td>
    <td width="50" align="center"><b>CABANG</b></td>
    <td width="50" align="center"><b>TOTAL</b></td>
   </tr>
   <tR>
    <td>Pegawai Tetap</td>
    <td align="right">
    <?
	// CATATAN
	// 1 -> tetap, 2 -> percobaan, 3 -> perjanjian kerja biasa, 4 -> perjanjian kerja khusus (lembaga), 
	// 5 -> perjanjian kerja khusus (individu) pkuwt, 6 -> harian, 7 -> honorer
	
	// pegawai tetap di SHO
    	$sSHO = mssql_query("select count(*) from vlatestkarir A, mstso B where (A.kode_so1=B.kode_so OR A.kode_so2=B.kode_so) AND (stat_kar1='1' OR stat_kar2='1') AND Jenis NOT IN ('U','H') AND AreaCode='SHO'",$conn);
		$rSHO = mssql_fetch_array($sSHO);
		echo"$rSHO[0]";
	?>
    </td>
    <td align="right">
    <?
	// pegawai tetap di SBU
    	$sSBU = mssql_query("select count(*) from vlatestkarir A, mstso B where (A.kode_so1=B.kode_so OR A.kode_so2=B.kode_so) AND (stat_kar1='1' OR stat_kar2='1') AND Jenis NOT IN ('U','H') AND AreaCode IN (SELECT IDCODE FROM VSBU)",$conn);
		$rSBU = mssql_fetch_array($sSBU);
		echo"$rSBU[0]";
	?>    
    </td>
    <td align="right">
    <?
	// pegawai tetap di CABANG
    	$sCBG = mssql_query("select count(*) from vlatestkarir A, mstso B where (A.kode_so1=B.kode_so OR A.kode_so2=B.kode_so) AND (stat_kar1='1' OR stat_kar2='1') AND Jenis NOT IN ('U','H') AND AreaCode IN (SELECT IDCODE FROM VCabangR)",$conn);
		$rCBG = mssql_fetch_array($sCBG);
		echo"$rCBG[0]";
	?>        
    </td>
    <td align="right">
    <?
    // total pegawai tetap di SBU, SHO, CBG
		echo ($rSBU[0]+$rSHO[0]+$rCBG[0]);
	?>
    </td>
   </tR>
   <tR>
    <td>Percobaan</td>
    <td align="right">
    <?
	// pegawai percobaan di SHO
    	$sCBSHO = mssql_query("select count(*) from vlatestkarir A, mstso B where (A.kode_so1=B.kode_so OR A.kode_so2=B.kode_so) AND (stat_kar1='2' OR stat_kar2='2') AND Jenis NOT IN ('U','H') AND AreaCode='SHO'",$conn);
		$rCBSHO = mssql_fetch_array($sCBSHO);
		echo"$rCBSHO[0]";
	?>
    </td>
    <td align="right">
    <?
	// pegawai percobaan di SBU
    	$sCBSBU = mssql_query("select count(*) from vlatestkarir A, mstso B where (A.kode_so1=B.kode_so OR A.kode_so2=B.kode_so) AND (stat_kar1='2' OR stat_kar2='2') AND Jenis NOT IN ('U','H') AND AreaCode IN (SELECT IDCODE FROM VSBU)",$conn);
		$rCBSBU = mssql_fetch_array($sCBSBU);
		echo"$rCBSBU[0]";
	?>    
    </td>
    <td align="right">
    <?
	// pegawai percobaan di CABANG
    	$sCBCBG = mssql_query("select count(*) from vlatestkarir A, mstso B where (A.kode_so1=B.kode_so OR A.kode_so2=B.kode_so) AND (stat_kar1='2' OR stat_kar2='2') AND Jenis NOT IN ('U','H') AND AreaCode IN (SELECT IDCODE FROM VCabangR)",$conn);
		$rCBCBG = mssql_fetch_array($sCBCBG);
		echo"$rCBCBG[0]";
	?>        
    </td>
    <td align="right">
    <?
    // total pegawai percobaan di SBU, SHO, CBG
		echo ($rCBSBU[0]+$rCBSHO[0]+$rCBCBG[0]);
	?>
    </td>
   </tR>
   <tR>
    <td>Kontrak Waktu Tertentu (PKUWT)</td>
    <td align="right">
    <?
	// perjanjian kerja biasa/PKUWT di SHO
    	$sSHO1 = mssql_query("select count(*) from vlatestkarir A, mstso B where (A.kode_so1=B.kode_so OR A.kode_so2=B.kode_so) AND (stat_kar1='5' OR stat_kar2='5') AND Jenis NOT IN ('U','H') AND AreaCode='SHO'",$conn);
		$rSHO1 = mssql_fetch_array($sSHO1);
		echo"$rSHO1[0]";
	?>
    </td>
    <td align="right">
    <?
	// perjanjian kerja biasa/PKUWT di SBU
    	$sCBSBU1 = mssql_query("select count(*) from vlatestkarir A, mstso B where (A.kode_so1=B.kode_so OR A.kode_so2=B.kode_so) AND (stat_kar1='5' OR stat_kar2='5') AND Jenis NOT IN ('U','H') AND AreaCode IN (SELECT IDCODE FROM VSBU)",$conn);
		$rCBSBU1 = mssql_fetch_array($sCBSBU1);
		echo"$rCBSBU1[0]";
	?>    
    </td>
    <td align="right">
    <?
	// perjanjian kerja biasa/PKUWT di CABANG
    	$sCBCBG1 = mssql_query("select count(*) from vlatestkarir A, mstso B where (A.kode_so1=B.kode_so OR A.kode_so2=B.kode_so) AND (stat_kar1='5' OR stat_kar2='5') AND Jenis NOT IN ('U','H') AND AreaCode IN (SELECT IDCODE FROM VCabangR)",$conn);
		$rCBCBG1 = mssql_fetch_array($sCBCBG1);
		echo"$rCBCBG1[0]";
	?>        
    </td>
    <td align="right">
    <?
    // perjanjian kerja biasa/PKUWT di SBU, SHO, CBG
		echo ($rCBSBU1[0]+$rSHO1[0]+$rCBCBG1[0]);
	?>
    </td>
   </tR>
   <tR>
    <td>Outsourching</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
   </tR>   
   <tr>
    <td align="left" style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;"><b><i>TOTAL</i></b></td>
    <td align="right"  style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;"><b>&nbsp;</b></td>
    <td style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;">&nbsp;</td>     
    <td style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;">&nbsp;</td>     
    <td style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;">&nbsp;</td>             
   </tr>
  </table>
  </td>
 </tr>
 <tr>
  <td><br>
  III. BERDASARKAN TINGKAT PENDIDIKAN *)<br><br>
  <table width="100%" cellpadding="2" border="1" cellspacing="0">
   <tr bgcolor="#CCCCCC">
    <td><b>Tingkat Pendidikan</b></td>
    <td><b>Jumlah</b></td>
    <td><b>Presentase</b></td>
   </tr>
<?
// get jenjang pendidikan
// JANGAN LUPA UNTUK CEK STATUS KARYAWAN TETAP,PERCOBAAN DARI TABLE KARIR PTSI
// total 
	$qquery	= mssql_query("SELECT count(*) FROM VLatestKarir A, VLatestPend B WHERE A.NIK=B.NIK AND (A.stat_kar1 IN ('1','2') OR A.stat_kar2 IN ('1','2')) AND Jenis NOT IN ('U','H') ",$conn);
	$qtotal	= mssql_fetch_array($qquery);
	//echo"<b>$TRDF</b>";
	$sp 	= mssql_query("
	WITH limit AS (
	SELECT CASE keterangan 
		WHEN 'SD' THEN '1' 
		WHEN 'SMP' THEN '2' 
		WHEN 'SMA' THEN '3' 
		WHEN 'D1' THEN '4' 
		WHEN 'D2' THEN '5' 
		WHEN 'D3' THEN '6' 
		WHEN 'D4' THEN '7' 
		WHEN 'S1' THEN '8' 
		WHEN 'S2' THEN '9' 
		WHEN 'S3' THEN '10' 
	END AS jenjang, keterangan
	FROM MstPendidikan WHERE keterangan NOT IN ('SD Lain-lain', 'LAIN-LAIN', 'SMP Lain-lain', 'SMKK','STM','ST','SMEA','SMK')
	GROUP BY keterangan )
	SELECT * FROM limit ORDER BY jenjang ASC
	",$conn);
	while($rp = mssql_fetch_array($sp)){
		echo"
		<tr>
		 <td>";
		 if($rp[jenjang] == "2"){
		 	echo"SMA/SMK/STM/SMEA/SMKK";
		 }
		 else{
		 	echo"$rp[keterangan]";
		 }
		 echo"</td><td align='right'>";
		 // get jumlah 
		 //$SDF 	= mssql_query("SELECT * FROM VRepJenjangNIK WHERE jenjang_pend='".($rp[jenjang]+1)."'",$conn);
//		 $SSDF	= mssql_query("WITH G AS (SELECT A.NIK,jenjang_pend FROM VLatestKarir A, VRepJenjangNIK B WHERE A.NIK=B.NIK AND (stat_kar1 IN ('1','2') OR stat_kar2 IN ('1','2'))) SELECT * FROM G WHERE jenjang_pend='".$rp[jenjang]."'",$conn);
		 $SSDF	= mssql_query("WITH G AS (SELECT A.NIK,kode_jenjang FROM VLatestKarir A, VLatestPend B WHERE A.NIK=B.NIK AND (stat_kar1 IN ('1','2') OR stat_kar2 IN ('1','2')) AND Jenis NOT IN ('U','H')) SELECT * FROM G WHERE kode_jenjang='".$rp[jenjang]."'",$conn);

		 $RRDF	= mssql_num_rows($SSDF);
		 echo"$RRDF";
		 echo"</td><td align=right>";
		 if($RRDF == 0){
		 	echo"0";
		 }
		 else{
		 	echo round((($RRDF/$qtotal[0])*100),2);
		 }
		 echo"%</td></tr>";
	}
?>
   <tr>
    <td align="left" style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;"><b><i>TOTAL</i></b></td>
    <td align="right"  style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;"><b><?=$qtotal[0]?> </b></td>
    <td style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;">&nbsp;</td>     
   </tr>
<?
// get pendidikan
?>
  </table>&nbsp;
  <i><small>*) Hanya Status Pegawai Tetap &amp; Percobaan</small></i>
  </td>
 </tr>
 <tr>
  <td><br>
  IV. BERDASARKAN TINGKAT JABATAN<br><br>
  <table width="100%" cellpadding="2" border="1" cellspacing="0">
   <tr bgcolor="#CCCCCC">
    <td><b>Tingkat Jabatan</b></td>
    <td><b>Jumlah</b></td>
    <td><b>Presentase</b></td>
   </tr>
   <tr>
    <td colspan="3"><b>Pegawai <i>(Tetap &amp; Percobaan)</i></b></td>
   </tr>
   <tr>
    <td>Fungsional</td>
    <td align="right">
    <?
	// total struktur dan fungsional
	$qrtotal	= mssql_query("SELECT count(*) FROM VLatestKarir WHERE (stat_kar1 IN ('1','2') OR stat_kar2 IN ('1','2'))");
	$rqtotal	= mssql_fetch_array($qrtotal);
	// get jumlah fungsional
	$qfungsi	= mssql_query("SELECT count(*) FROM VLatestKarir WHERE (stat_kar1 IN ('1','2') OR stat_kar2 IN ('1','2')) AND (fungsi1 NOT IN ('000','NULL','999') OR fungsi2 NOT IN ('000','NULL','999') )",$conn);    
	$rfungsi	= mssql_fetch_array($qfungsi);
	echo"$rfungsi[0]";
	?>
    </td>
    <td align="right">
        <?
    	if($rfungsi[0] == 0){
			echo"0";
		}
		else{
			echo round(($rfungsi[0]/$rqtotal[0])*100,2);
		}
	?>%</td>
   </tr>
   <tr>
    <td>Struktural</td>
    <td align="right">
<?
	// get jumlah struktural
	//$qstruk		= mssql_query("SELECT count(*) FROM VLatestKarir WHERE (stat_kar1 IN ('1','2') OR stat_kar2 IN ('1','2')) AND (fungsi1 IN (SELECT kode FROM MstFungsional WHERE kode NOT IN ('999')) OR fungsi2 IN (SELECT kode FROM MstFungsional WHERE kode NOT IN ('999')) )",$conn);    
	//$rstruk		= mssql_fetch_array($qstruk);
	//echo"$rstruk[0]";
	$jumlah_struktural = ($rqtotal[0]-$rfungsi[0]);
	echo"$jumlah_struktural";
?>    
    </td>
    <td align="right">
    <?
    	if($jumlah_struktural == 0){
			echo"0";
		}
		else{
			echo round(($jumlah_struktural/$rqtotal[0])*100,2);
		}
	?>%</td>
   </tr>
   <tr>
    <td align="right"><b><i>Subtotal</i></b></td>
    <td align="right"><?=$rqtotal[0]?></td>
    <td>&nbsp;</td>
   </tr>   
   <tr>
    <td colspan="3">
     <table width="100%" border="1" cellpadding="2" cellspacing="0">
      <tr>
       <td width="200"><b>Non Pegawai</b></td>
       <td width="100"><b><i>Kontrak Khusus</i></b></td>
       <td width="100"><b><i>Kopsurindo</i></b></td>
       <td width="100"><b>Sub Total</b></td>
       <td width="100">&nbsp;</td>
      </tr>
      <tr>
       <td>Fungsional</td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
      </tr>
      <tr>
       <td>Struktural</td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
      </tr>
      <tr>
       <td align="right"><i>Sub Total</i></td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
       <td>&nbsp;</td>
      </tr>
	  <tr>
    	<td align="left" style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;"><b><i>TOTAL</i></b></td>
    	<td align="right"  style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;"><b>&nbsp;</b></td>
    	<td style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;">&nbsp;</td>     
        <td style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;">&nbsp;</td>     
        <td style="border-bottom:solid 2px #000000; border-top:solid 2px #000000;">&nbsp;</td>     
   	  </tr>
     </table>
    </td>
   </tr>
<?
// get pendidikan
?>
  </table>
  </td>
 </tr>
</table>
<?
//*///
if($HTTP_GET_VARS['excel'] == "yes"){
	header('Content-type: application/vnd.ms-excel');
	header("Content-Disposition: attachment; filename=KomposisiTenagaKerjaKaryawandotnet.xls");
	header("Pragma: no-cache");
	header("Expires: 0");
	}
else{

}
//	*/
?>